package gui;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.UIManager;
import javax.swing.border.LineBorder;
import java.awt.Font;

public class MiniGame extends JPanel {
	private JLabel block1;
	private JLabel block2;
	private JLabel block3;
	private JLabel block4;
	private JLabel block5;
	private JLabel block6;
	private JLabel block7;
	private JLabel block8;
	private JLabel block9;
	/*static int rows,cols=3;
	int[][] getGame = {{Integer.parseInt(block1.getText()),Integer.parseInt(block2.getText()),Integer.parseInt(block3.getText())},
				   {Integer.parseInt(block4.getText()),Integer.parseInt(block5.getText()),Integer.parseInt(block6.getText())},
				   {Integer.parseInt(block7.getText()),Integer.parseInt(block8.getText()),Integer.parseInt(block9.getText())}};
	
	*/

	/**
	 * Create the panel.
	 */
	public MiniGame() {
		setSize(new Dimension(450, 500));
		setBorder(new LineBorder(new Color(139, 0, 0)));
		setBackground(new Color(250, 128, 114));
		
		setLayout(null);
		add(getBlock1());
		add(getBlock2());
		add(getBlock3());
		add(getBlock4());
		add(getBlock5());
		add(getBlock6());
		add(getBlock9());
		add(getBlock8());
		add(getBlock7());

	}

	private JLabel getBlock1() {
		if (block1 == null) {
			block1 = new JLabel("0");
			block1.setFont(new Font("굴림", Font.BOLD, 30));
			block1.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					if(block2.getText()=="0"){
						block2.setText("1");
					}else{
						block2.setText("0");
					}
					if(block4.getText()=="0"){
						block4.setText("1");
					}else{
						block4.setText("0");
					}
					if(block5.getText()=="0"){
						block5.setText("1");
					}else{
						block5.setText("0");
					}
					
				}
			});
			block1.setHorizontalAlignment(SwingConstants.CENTER);
			block1.setBounds(12, 10, 50, 50);
		}
		return block1;
	}
	private JLabel getBlock2() {
		if (block2 == null) {
			block2 = new JLabel("0");
			block2.setFont(new Font("굴림", Font.BOLD, 30));
			block2.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					if(block1.getText()=="0"){
						block1.setText("1");
					}else{
						block1.setText("0");
					}
					if(block3.getText()=="0"){
						block3.setText("1");
					}else{
						block3.setText("0");
					}
					if(block4.getText()=="0"){
						block4.setText("1");
					}else{
						block4.setText("0");
					}
					if(block5.getText()=="0"){
						block5.setText("1");
					}else{
						block5.setText("0");
					}
					if(block6.getText()=="0"){
						block6.setText("1");
					}else{
						block6.setText("0");
					}
				}
			});
			block2.setHorizontalAlignment(SwingConstants.CENTER);
			block2.setBounds(74, 10, 50, 50);
		}
		return block2;
	}
	private JLabel getBlock3() {
		if (block3 == null) {
			block3 = new JLabel("0");
			block3.setFont(new Font("굴림", Font.BOLD, 30));
			block3.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					if(block2.getText()=="0"){
						block2.setText("1");
					}else{
						block2.setText("0");
					}
					if(block5.getText()=="0"){
						block5.setText("1");
					}else{
						block5.setText("0");
					}
					if(block6.getText()=="0"){
						block6.setText("1");
					}else{
						block6.setText("0");
					}
				}
			});
			block3.setHorizontalAlignment(SwingConstants.CENTER);
			block3.setBounds(136, 10, 50, 50);
		}
		return block3;
	}
	private JLabel getBlock4() {
		if (block4 == null) {
			block4 = new JLabel("0");
			block4.setFont(new Font("굴림", Font.BOLD, 30));
			block4.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					if(block1.getText()=="0"){
						block1.setText("1");
					}else{
						block1.setText("0");
					}
					if(block2.getText()=="0"){
						block2.setText("1");
					}else{
						block2.setText("0");
					}
					if(block5.getText()=="0"){
						block5.setText("1");
					}else{
						block5.setText("0");
					}
					if(block7.getText()=="0"){
						block7.setText("1");
					}else{
						block7.setText("0");
					}
					if(block8.getText()=="0"){
						block8.setText("1");
					}else{
						block8.setText("0");
					}
				}
			});
			block4.setHorizontalAlignment(SwingConstants.CENTER);
			block4.setBounds(12, 70, 50, 50);
		}
		return block4;
	}
	private JLabel getBlock5() {
		if (block5 == null) {
			block5 = new JLabel("0");
			block5.setFont(new Font("굴림", Font.BOLD, 30));
			block5.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					if(block1.getText()=="0"){
						block1.setText("1");
					}else{
						block1.setText("0");
					}
					if(block2.getText()=="0"){
						block2.setText("1");
					}else{
						block2.setText("0");
					}
					if(block3.getText()=="0"){
						block3.setText("1");
					}else{
						block3.setText("0");
					}
					if(block4.getText()=="0"){
						block4.setText("1");
					}else{
						block4.setText("0");
					}
					if(block6.getText()=="0"){
						block6.setText("1");
					}else{
						block6.setText("0");
					}
					if(block7.getText()=="0"){
						block7.setText("1");
					}else{
						block7.setText("0");
					}
					if(block8.getText()=="0"){
						block8.setText("1");
					}else{
						block8.setText("0");
					}
					if(block9.getText()=="0"){
						block9.setText("1");
					}else{
						block9.setText("0");
					}
				}
			});
			block5.setHorizontalAlignment(SwingConstants.CENTER);
			block5.setBounds(74, 70, 50, 50);
		}
		return block5;
	}
	private JLabel getBlock6() {
		if (block6 == null) {
			block6 = new JLabel("0");
			block6.setFont(new Font("굴림", Font.BOLD, 30));
			block6.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					if(block2.getText()=="0"){
						block2.setText("1");
					}else{
						block2.setText("0");
					}
					if(block3.getText()=="0"){
						block3.setText("1");
					}else{
						block3.setText("0");
					}
					if(block5.getText()=="0"){
						block5.setText("1");
					}else{
						block5.setText("0");
					}
					if(block8.getText()=="0"){
						block8.setText("1");
					}else{
						block8.setText("0");
					}
					if(block9.getText()=="0"){
						block9.setText("1");
					}else{
						block9.setText("0");
					}
				}
			});
			block6.setHorizontalAlignment(SwingConstants.CENTER);
			block6.setBounds(136, 70, 50, 50);
		}
		return block6;
	}
	private JLabel getBlock7() {
		if (block7 == null) {
			block7 = new JLabel("0");
			block7.setFont(new Font("굴림", Font.BOLD, 30));
			block7.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					if(block4.getText()=="0"){
						block4.setText("1");
					}else{
						block4.setText("0");
					}
					if(block5.getText()=="0"){
						block5.setText("1");
					}else{
						block5.setText("0");
					}
					if(block8.getText()=="0"){
						block8.setText("1");
					}else{
						block8.setText("0");
					}
				}
			});
			block7.setHorizontalAlignment(SwingConstants.CENTER);
			block7.setBounds(12, 130, 50, 50);
		}
		return block7;
	}	
	private JLabel getBlock8() {
		if (block8 == null) {
			block8 = new JLabel("0");
			block8.setFont(new Font("굴림", Font.BOLD, 30));
			block8.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					if(block4.getText()=="0"){
						block4.setText("1");
					}else{
						block4.setText("0");
					}
					if(block5.getText()=="0"){
						block5.setText("1");
					}else{
						block5.setText("0");
					}
					if(block6.getText()=="0"){
						block6.setText("1");
					}else{
						block6.setText("0");
					}
					if(block7.getText()=="0"){
						block7.setText("1");
					}else{
						block7.setText("0");
					}
					if(block9.getText()=="0"){
						block9.setText("1");
					}else{
						block9.setText("0");
					}
				}
			});
			block8.setHorizontalAlignment(SwingConstants.CENTER);
			block8.setBounds(74, 130, 50, 50);
		}
		return block8;
	}
	private JLabel getBlock9() {
		if (block9 == null) {
			block9 = new JLabel("0");
			block9.setFont(new Font("굴림", Font.BOLD, 30));
			block9.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseClicked(MouseEvent arg0) {
					if(block5.getText()=="0"){
						block5.setText("1");
					}else{
						block5.setText("0");
					}
					if(block6.getText()=="0"){
						block6.setText("1");
					}else{
						block6.setText("0");
					}
					if(block8.getText()=="0"){
						block8.setText("1");
					}else{
						block8.setText("0");
					}
				}
			});
			block9.setHorizontalAlignment(SwingConstants.CENTER);
			block9.setBounds(136, 130, 50, 50);
		}
		return block9;
	}
	
}
